<div class="page-template-template-tags-php">
<div class="page-title">Categories</div>

            
<div class="hentry-content clear">
                <div class="tags">
                    <?php
					$args = array(  'type'  		=> 'post',
									'orderby'   	=> 'name',
									'order'     	=> 'ASC',
									'pad_counts'	=> 0
									);
									
                        $cates = get_categories($args);
						/*print_r($cates);
						exit;*/
                        $capital = '';
                        $i = 0; // iterator
                        $cut = ceil( count($cates)/4 ); // number of cates at column
						/*echo 'cut '.$cut; exit;*/
                        $cutter = $cut;
                        $letter_i = 0;
                        $output = '<div class="column">';
                        foreach ( $cates as $cat ) {
                            $i++;
                            $firstletter = mb_strtolower( mb_substr($cat->name, 0, 1) );
                            if ( $firstletter !=  $capital ) {
                                $letter_i++;
                                if ( $letter_i != 1 ) $output .= '</ul>';
                                if ( $i > $cutter ) {
                                    $output .= '</div><div class="column">';
                                    $cutter = $cutter + $cut;
                                }
                                $capital = $firstletter;
                                $output .= '<h4>' . $capital . '</h4><ul>';
                            }
                            $term = get_term_by('id', (int)$cat->cat_ID, 'category');
                            $output .= '<li><a href="' . get_category_link( (int)$cat->cat_ID) . '">' . $cat->name . '</a> (' . $term->count . ')</li>';
                        }
                        echo $output . '</ul></div>';
                    ?>
                </div>
            </div>
</div>